<?php
/**
 * NetBiz Framework
 * Copyright (C) 20009 - 2010 NetBiz
 * 
 * All rights reserved.
 */

class FRM_Template extends FRM_View
{
	protected $_template_file = '';
	protected $_variables = array();

	public function __construct($template = '')
	{
		$this->_template_file = $template;
	}

	public function __get($name)
	{
		return @$this->_variables[$name];
	}

	public function __set($name,$value)
	{
		$this->_variables[$name] = $value;
	}

	public function render()
	{
		$smarty = FRM::load('smarty');
		
		// Export variables onto Smarty
		foreach($this->_variables as $name => $value)
		{
			$smarty->assign($name,$value);
		}
		
		// Export views onto Smarty
		// We use objects here to delay the actual rendering to the
		// time of use. It avoids conflict as well and we restrict
		// callable function set to only "render"
		foreach($this->_views as $name => $value)
		{
			$smarty->register_object($name,$value,array('render'));
		}

		return $smarty->fetch($this->_template_file);
	}
}